package com.newworld.dmsapp2.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.webkit.WebSettings.ZoomDensity;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.newworld.dmsapp2.util.Config;
import com.newworld.dmsapp2.util.Tool;

@SuppressLint("NewApi")
public class WebShowActivity extends Activity {

	private static MineWebView mWv;
	private static int DOWNLOAD_SUSSCESS = 1;
	static Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			if (msg.what == DOWNLOAD_SUSSCESS) {
				mWv.loadUrl(Config.APP_DETAIL_WEB);
			}
			super.handleMessage(msg);
		}
	};

	@SuppressWarnings({ "deprecation", "static-access" })
	@SuppressLint("NewApi")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mWv = new MineWebView(this);
		mWv.getSettings().setJavaScriptEnabled(true);
		mWv.getSettings().setSupportZoom(true);
		mWv.getSettings().setJavaScriptEnabled(true);
		mWv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
		mWv.getSettings().setBuiltInZoomControls(true);// support zoom
		mWv.getSettings().setPluginState(mWv.getSettings().getPluginState().ON);// support
																				// flash
		mWv.getSettings().setUseWideViewPort(true);// 这个很关键
		mWv.getSettings().setLoadWithOverviewMode(true);

		DisplayMetrics metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metrics);
		int mDensity = metrics.densityDpi;
		if (mDensity == 240) {
			mWv.getSettings().setDefaultZoom(ZoomDensity.FAR);
		} else if (mDensity == 160) {
			mWv.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
		} else if (mDensity == 120) {
			mWv.getSettings().setDefaultZoom(ZoomDensity.CLOSE);
		} else if (mDensity == DisplayMetrics.DENSITY_XHIGH) {
			mWv.getSettings().setDefaultZoom(ZoomDensity.FAR);
		} else if (mDensity == DisplayMetrics.DENSITY_TV) {
			mWv.getSettings().setDefaultZoom(ZoomDensity.FAR);
		}
		mWv.getSettings().setDefaultTextEncodingName("utf-8"); // 设置默认为utf-8
		mWv.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) { // 重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
				return false;
			}
		});
		mWv.loadUrl(Config.APP_DETAIL_WEB);
		setContentView(mWv);
	}

	protected class MineWebView extends WebView {

		public MineWebView(Context context) {
			super(context);
		}

	}

}
